package co.th.bjc.md.dbonline.control;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import co.th.bjc.md.dbonline.bean.ProductDBOnlineBean;
import co.th.bjc.md.helper.ProductHelper;
import co.th.bjc.md.model.Product;

public class ProductDBOnlineControl {

	private static Logger _log = Logger.getLogger(ProductDBOnlineControl.class);
	
	public List<ProductDBOnlineBean> findProductByCategoryAndBrand(BigDecimal category, BigDecimal brand){
		List<ProductDBOnlineBean> list = new ArrayList<ProductDBOnlineBean>(0);
		try {
			List<Product> listProduct = new ProductHelper().findProductByCategoryAndBrand(category, brand);
			for (Product product : listProduct) {
				ProductDBOnlineBean bean = new ProductDBOnlineBean();
				bean.setProductCode(product.getProductCode());
				bean.setProductYear(product.getProductYear());
				bean.setProductNameTh(product.getProductNameTh());
				bean.setProductNameEn(product.getProductNameEn());
				bean.setProductDetail(product.getProductDetail());
				bean.setImage(product.getImage());
				list.add(bean);
			}
		} catch (Exception ex) {
			_log.error("Exception : " + ex.getMessage());
			ex.printStackTrace();
		}
		return list;
	}
}
